shopping_list=[]
listGoods = [("iphone",1000),("bike",400),("mac",300)]
salary = input("Please input your sarlary:")
if salary.isdigit():
    salary = int(salary)
# for item in listGoods:
#     print(listGoods.index(item),item)#取下标
    while True:
        for index,item in enumerate(listGoods):#取下标
            print(index,item)
        user_choice = input("please choose your things:")
        if user_choice.isdigit():
            user_choice = int(user_choice)
            if user_choice <= len(listGoods) and user_choice >= 0:
                p_item = listGoods[user_choice]
                if p_item[1] <= salary: #买得起
                    shopping_list.append(p_item)
                    salary -= p_item[1]
                    print("Added %s into shopping cart,your current balance is %s"%(user_choice,salary))
                else:
                    print("余额不足！")
            else:
                print("所选的商品无效！")
        elif user_choice == 'q':
            print('--------shopping list-------------!')
            for p in shopping_list:
                print(p)
            print("所剩余额是： %s"%(salary))
            break
        else:
            print("invalid option")
else:
    print("invalid option")
